Scheduled Processes Lab
1. Schedule System Cron Jobs
In this lab, you work with recurring system jobs. You run a daily job to count the number of active users, and an updated cron job to gather system performance data.
Log in to your
desktop1.example.comsystem asstudent, then elevate your privileges toroot.[student@desktop1 ~]$ su - Password: r3dh@t1!
Create a new daily cron job that logs a message to the system log with the number of currently active users
(w -h | wc -l). You can use theloggercommand to send messages to the system log.Using an editor, open a new file in
/etc/cron.daily, e.g./etc/cron.daily/usercount.[root@desktop1 ~]# vim /etc/cron.daily/usercount
Write the script that logs the number of active users to the system log. Insert the following in your editor:
#!/bin/bash USERCOUNT=$(w -h | wc -l) logger "There are currently ${USERCOUNT} active users"Make the script executable.
[root@desktop1 ~]# chmod +x /etc/cron.daily/usercount
The
sysstatpackage, when installed, has a cron job that runs every 10 minutes, collecting data using a command calledsa1. Make sure this package is installed, then change this job to run every five minutes.Make sure the
sysstatpackage is installed.[root@desktop1 ~]# yum -y install sysstat
Find out in which file the
sysstatpackage has configured the cron jobs. Cron jobs are generally configured in files marked as a configuration file for the package manager.[root@desktop1 ~]# rpm -qc sysstat
/etc/cron.d/sysstatlooks promising.
Open
/etc/cron.d/sysstatin an editor.[root@desktop1 ~]# vim /etc/cron.d/sysstat
Change
*/10on thesa1line to*/5, then save your changes and exit.Monitor the files in
/var/log/sato see when their sizes and timestamps change.[root@desktop1 ~]# watch ls -l /var/log/sa
2. Manage Temporary Files
In this lab, you configure your system to purge files older than 5 days from /tmp.
You also add a new automatically created temporary directory called /run/gallifrey, in which
files that have been unused for more than 30 seconds are automatically purged.
Reset your
server1.example.comsystem./tmpis undersystemd-tmpfilescontrol. To override the upstream settings, copy/usr/lib/tmpfiles.d/tmp.confto/etc/tmpfiles.d/.[root@server1 ~]# cp /usr/lib/tmpfiles.d/tmp.conf /etc/tmpfiles.d/
Find the line in
/etc/tmpfiles.d/tmp.confthat controls the purging interval for/tmp, and change the interval from10dto5d. You can open/etc/tmpfiles.d/tmp.confin an editor and make the change, or use the following command:[root@server1 ~]# sed -i '/^d .tmp /s/10d/5d/' /etc/tmpfiles.d/tmp.conf
Test if
systemd-tmpfiles --cleanaccepts the new configuration.[root@server1 ~]# systemd-tmpfiles --clean tmp.conf
Create a new configuration file
/etc/tmpfiles.d/gallifrey.confwith the following content:# Set up /run/gallifrey, owned by root with 0700 permissions # Files not used for 30 seconds will be automatically deleted d /run/gallifrey 0700 root root 30s
Test your new configuration for creating
/run/gallifrey.[root@server1 ~]# systemd-tmpfiles --create gallifrey.conf
[root@server1 ~]# ls -ld /run/gallifrey drwx------. 2 root root Feb 19 10:29 /run/gallifrey
Test the purging of your
/run/gallifreydirectory.Create a new file under
/run/gallifrey.[root@server1 ~]# touch /run/gallifrey/companion
Wait for at least 30 seconds.
[root@server1 ~]# sleep 30s
Have
systemd-tmpfilesclean the/run/gallifreydirectory.[root@server1 ~]# systemd-tmpfiles --clean gallifrey.conf
Inspect the contents of
/run/gallifrey.[root@server1 ~]# ls -l /run/gallifrey